package com.cssw.fyzb.busi.api.appeal;

import com.cssw.fyzb.busi.api.task.CollecTask;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.UUID;

/**
 * @author
 */
@Function(description = "图片上传", parameters = {
        @Parameter(name = "file", type = Type.String, description = "申述标识", required = true)
})
@Component
public class FileAppeal implements Action {
    public static final String IMG_URL_ADDRDRS = "";

    private final static Logger logger = LoggerFactory.getLogger(CollecTask.class);

    @Override
    public Response execute(Request request) throws Exception {
        String filename = "picture_" + UUID.randomUUID() + ".jpg";//生成唯一图片路径
        String file = request.getString("file");
        if (!file.isEmpty()) {
            try {
                File filepath = new File(IMG_URL_ADDRDRS);
                if (!filepath.exists()) {
                    filepath.mkdir();
                    //文件保存路径
                    String savePath = IMG_URL_ADDRDRS + filename;
                    //转存文件
                    
                }
            } catch (Exception e) {
                logger.debug("", e);
                return Response.fail("图片上传失败");
            }
        }
        return null;
    }
}
